


PACKAGE BODY Console_Interface IS




  FUNCTION File_Chooser (Dir : IN String ; Ext : IN String) RETURN Ada.Strings.Unbounded.Unbounded_String IS

    File_Name      : Ada.Strings.Unbounded.Unbounded_String;
    File_Counter   : Integer := 1;
    File_List      : ARRAY (1 .. 100) OF Ada.Strings.Unbounded.Unbounded_String;
    File_Selection : String (1 .. 4);
    Last           : Natural;
    PACKAGE Int_IO IS NEW Ada.Text_IO.Integer_IO (Integer);

    PROCEDURE Walk (Name : String; Pattern : String) IS
      PROCEDURE Print (Item : Ada.Directories.Directory_Entry_Type) IS
      BEGIN
	Ada.Text_IO.Put_Line ("[" & Integer'Image (File_Counter) & "] - " & Ada.Directories.Simple_Name (Item));

	File_List (File_Counter) := Ada.Strings.Unbounded.To_Unbounded_String (Ada.Directories.Simple_Name (Item));
	File_Counter := File_Counter + 1;
      END Print;
      PROCEDURE Walk (Item : Ada.Directories.Directory_Entry_Type) IS
      BEGIN
	IF Ada.Directories.Simple_Name (Item) /= "." AND THEN Ada.Directories.Simple_Name (Item) /= ".." THEN
	  --Walk (Ada.Directories.Full_Name (Item), Pattern);
	  NULL;
	END IF;
      EXCEPTION
	WHEN Ada.Directories.Name_Error => NULL;
      END Walk;
    BEGIN
      Ada.Directories.Search (Name, Pattern, (OTHERS => True), Print'Access);
      Ada.Directories.Search (Name, "", (Ada.Directories.Directory => True, OTHERS => False), Walk'Access);
    END Walk;

  BEGIN
    Ada.Text_Io.Put_Line ("-----------------------------------------------");
    Ada.Text_Io.Put_Line ("Fichiers XML disponibles dans le dossier data :");
    Ada.Text_Io.Put_Line ("-----------------------------------------------");
    Ada.Text_Io.New_Line;
    Walk (Dir, Ext);
    Ada.Text_Io.New_Line;


    LOOP

      Ada.Text_Io.Put_Line ("Veuillez saisir le numero d'un fichier :");
      Ada.Text_Io.Put_Line ("----------------------------------------");

      Ada.Text_Io.Flush;
      Ada.Text_Io.Get_Line (File_Selection, Last);
      IF Last /= 0 THEN
	File_Name := File_List (Integer'Value (File_Selection (1 .. Last)));
	Ada.Text_Io.New_Line;

	IF Integer'Value (File_Selection (1 .. Last)) < File_Counter THEN
	  EXIT WHEN Ada.Directories.Exists (Dir & Ada.Strings.Unbounded.To_String (File_Name));
	END IF;
      END IF;


    END LOOP;

    Ada.Text_Io.Put_Line ("Fichier selectionner : " & Ada.Strings.Unbounded.To_String (File_Name));
    Ada.Text_Io.Put_Line ("---------------------");
    RETURN Ada.Strings.Unbounded.To_Unbounded_String (Dir &  Ada.Strings.Unbounded.To_String (File_Name));
  END File_Chooser;


  PROCEDURE Clear IS

  BEGIN Ada.Text_IO.Put (ASCII.ESC & "[2J");
  END Clear;


  PROCEDURE Waiting_Message (Message : IN String; Time : IN Duration) IS

    Timer        : Duration := 0.4;
    Time_Counter : Duration := 0.0;
    Loop_Counter : Integer := 1;

  BEGIN
    LOOP
      Clear;
      Ada.Text_IO.New_Line;
      Ada.Text_IO.Put (Message);
      FOR I IN 0 .. (Loop_Counter MOD 3) LOOP
	Ada.Text_IO.Put (".");
      END LOOP;

      Loop_Counter := Loop_Counter + 1;

      DELAY Timer;
      Time_Counter := Time_Counter + Timer;
      EXIT WHEN Time_Counter >= Time;
    END LOOP;
    Clear;
    Ada.Text_IO.New_Line;
  END Waiting_Message;

  PROCEDURE Put_Title (Message : IN String) IS

  BEGIN
    Ada.Text_IO.Put_Line ("-------------------------------------");
    Ada.Text_IO.Put_Line (Ada.Characters.Handling.To_Upper (Message));
    Ada.Text_IO.Put_Line ("-------------------------------------");

  END Put_Title;
  PROCEDURE Put_Sub_Title (Message : IN String) IS

  BEGIN
    Ada.Text_IO.Put_Line (Ada.Characters.Handling.To_Upper (Message));
    Ada.Text_IO.Put_Line ("-------------------------------------");

  END Put_Sub_Title;


END Console_Interface;
